﻿/// Write a method that calculates the number of workdays between today and given date, passed as parameter.
/// Consider that workdays are all days from Monday to Friday except a fixed list of public holidays specified preliminary as array.


/* Write a method that calculates the number of workdays between 
 * today and given date, passed as parameter. Consider that workdays
 * are all days from Monday to Friday except a fixed 
 * list of public holidays specified preliminary as array.
 */

using System;

namespace c_sh_II_lek_4_classes
{
    public class zad5
    {
        public static DateTime[] holidays = 
        { 
            new DateTime(2013, 1, 1), 
            new DateTime(2013, 2, 5), 
            new DateTime(2013, 3, 3), 
            new DateTime(2013, 4, 4), 
        };

        public static void Main()
        {
            Console.WriteLine("Enter End Date - format (YYYY/MM/DD):");
            string[] endDateStr = Console.ReadLine().Split('/');
            int day = int.Parse(endDateStr[2]);
            int month = int.Parse(endDateStr[1]);
            int year = int.Parse(endDateStr[0]);

            DateTime startDay = DateTime.Today;
            DateTime endDay = new DateTime(year, month, day);
            int timeLen = (endDay - startDay).Days;




            int count = 0;
            DateTime countDay = startDay;

            for (int i = 0; i < timeLen; i++)
            {
                if (countDay.DayOfWeek != DayOfWeek.Sunday && countDay.DayOfWeek != DayOfWeek.Saturday && !IsHoliday(countDay))
                {
                    count++;
                }

                countDay = countDay.AddDays(1);
            }

            Console.WriteLine("There are {0} Working Days Beetwen Today ({1}) and {2} {3}", count, startDay.ToString("yyyy/MM/dd"), endDay.ToString("yyyy/MM/dd"), endDay.DayOfWeek);
        }

        private static bool IsHoliday(DateTime countDay)
        {
            bool isHoliday = false;
            for (int i = 0; i < holidays.Length; i++)
            {
                if (countDay == holidays[i])
                {
                    isHoliday = true;
                }
            }
            return isHoliday;
        }
    }
}